﻿using System;
using SEXY;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x02000551 RID: 1361
	[Serializable]
	public class UI_ColorPicker : UI_ColorSlider
	{
		// Token: 0x060022BC RID: 8892 RVA: 0x000D1220 File Offset: 0x000CF420
		protected override void Init()
		{
			base.Init();
			for (int i = 0; i < 2; i++)
			{
				if (this.imgPicker[i])
				{
					this.texPickerRect[i] = (this.imgPicker[i].mainTexture as Texture2D);
					this.texPickerSize[i].x = (float)this.texPickerRect[i].width;
					this.texPickerSize[i].y = (float)this.texPickerRect[i].height;
				}
			}
			if (this.tfPickerMode[(int)this.pickerMode])
			{
				Toggle component = this.tfPickerMode[(int)this.pickerMode].GetComponent<Toggle>();
				if (component)
				{
					component.isOn = true;
				}
			}
			this.ChangePickerMode();
		}

		// Token: 0x060022BD RID: 8893 RVA: 0x000D12F4 File Offset: 0x000CF4F4
		public void ChangePickerMode(UI_Parameter param)
		{
			if (null == param)
			{
				return;
			}
			Toggle component = param.GetComponent<Toggle>();
			if (component && component.isOn)
			{
				UI_ColorPicker.PickerMode pickerMode = (UI_ColorPicker.PickerMode)Enum.ToObject(typeof(UI_ColorPicker.PickerMode), param.index);
				if (this.pickerMode == pickerMode)
				{
					return;
				}
				this.pickerMode = pickerMode;
				this.ChangePickerMode();
			}
		}

		// Token: 0x060022BE RID: 8894 RVA: 0x000D1360 File Offset: 0x000CF560
		private void ChangePickerMode()
		{
			this.disableSetColor = true;
			this.ChangePickerRectPos();
			this.ChangePickerSliderPos();
			this.ChangePickerRectColor();
			this.ChangePickerSliderColor();
			this.disableSetColor = false;
		}

		// Token: 0x060022BF RID: 8895 RVA: 0x000D1388 File Offset: 0x000CF588
		public void OnChangePickerSliderValue(float value)
		{
			switch (this.pickerMode)
			{
			case UI_ColorPicker.PickerMode.Hue:
			{
				HsvColor colorHSV = base.GetColorHSV();
				colorHSV.H = value * 360f;
				base.SetColor(colorHSV, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			case UI_ColorPicker.PickerMode.Saturation:
			{
				HsvColor colorHSV2 = base.GetColorHSV();
				colorHSV2.S = value;
				base.SetColor(colorHSV2, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			case UI_ColorPicker.PickerMode.Value:
			{
				HsvColor colorHSV3 = base.GetColorHSV();
				colorHSV3.V = value;
				base.SetColor(colorHSV3, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			case UI_ColorPicker.PickerMode.Red:
			{
				Color colorRGB = base.GetColorRGB();
				colorRGB.r = value;
				base.SetColor(colorRGB, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			case UI_ColorPicker.PickerMode.Green:
			{
				Color colorRGB2 = base.GetColorRGB();
				colorRGB2.g = value;
				base.SetColor(colorRGB2, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			case UI_ColorPicker.PickerMode.Blue:
			{
				Color colorRGB3 = base.GetColorRGB();
				colorRGB3.b = value;
				base.SetColor(colorRGB3, UI_ColorInfo.ControlType.PickerSlider);
				break;
			}
			}
		}

		// Token: 0x060022C0 RID: 8896 RVA: 0x000D1478 File Offset: 0x000CF678
		public void OnChangePickerSliderValueA(float value)
		{
			base.SetAlpha(value, UI_ColorInfo.ControlType.PickerSliderA);
		}

		// Token: 0x060022C1 RID: 8897 RVA: 0x000D1484 File Offset: 0x000CF684
		public void OnChangePickerRectValue()
		{
			float x = this.infoPicker.imagePos.x;
			float y = this.infoPicker.imagePos.y;
			Vector2 anchoredPosition = this.rtfPickerPos.anchoredPosition;
			if (anchoredPosition.x != x || anchoredPosition.y != y)
			{
				this.rtfPickerPos.anchoredPosition = new Vector2(x, y);
				switch (this.pickerMode)
				{
				case UI_ColorPicker.PickerMode.Hue:
				{
					HsvColor colorHSV = base.GetColorHSV();
					colorHSV.S = this.infoPicker.imageRate.x;
					colorHSV.V = this.infoPicker.imageRate.y;
					base.SetColor(colorHSV, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				case UI_ColorPicker.PickerMode.Saturation:
				{
					HsvColor colorHSV2 = base.GetColorHSV();
					colorHSV2.H = this.infoPicker.imageRate.x * 360f;
					colorHSV2.V = this.infoPicker.imageRate.y;
					base.SetColor(colorHSV2, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				case UI_ColorPicker.PickerMode.Value:
				{
					HsvColor colorHSV3 = base.GetColorHSV();
					colorHSV3.H = this.infoPicker.imageRate.x * 360f;
					colorHSV3.S = this.infoPicker.imageRate.y;
					base.SetColor(colorHSV3, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				case UI_ColorPicker.PickerMode.Red:
				{
					Color colorRGB = base.GetColorRGB();
					colorRGB.b = this.infoPicker.imageRate.x;
					colorRGB.g = this.infoPicker.imageRate.y;
					base.SetColor(colorRGB, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				case UI_ColorPicker.PickerMode.Green:
				{
					Color colorRGB2 = base.GetColorRGB();
					colorRGB2.b = this.infoPicker.imageRate.x;
					colorRGB2.r = this.infoPicker.imageRate.y;
					base.SetColor(colorRGB2, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				case UI_ColorPicker.PickerMode.Blue:
				{
					Color colorRGB3 = base.GetColorRGB();
					colorRGB3.r = this.infoPicker.imageRate.x;
					colorRGB3.g = this.infoPicker.imageRate.y;
					base.SetColor(colorRGB3, UI_ColorInfo.ControlType.PickerRect);
					break;
				}
				}
			}
		}

		// Token: 0x060022C2 RID: 8898 RVA: 0x000D16C0 File Offset: 0x000CF8C0
		public void ChangePickerRectColor()
		{
			if (null == this.texPickerRect[0])
			{
				return;
			}
            //int num = (int)(this.pickerMode / UI_ColorPicker.PickerMode.Red);
            //int num2 = (int)(this.pickerMode % UI_ColorPicker.PickerMode.Red);
            int num = 0;
            int num2 = 1;
            int num3 = (int)this.texPickerSize[0].x;
			int num4 = (int)this.texPickerSize[0].y;
			Color[] array = new Color[num4 * num3];
			if (num == 0)
			{
				int[,] array2 = new int[,]
				{
					{
						1,
						2,
						0
					},
					{
						0,
						2,
						1
					},
					{
						0,
						1,
						2
					}
				};
				float[] rateHSV = base.GetRateHSV();
				for (int i = 0; i < num4; i++)
				{
					for (int j = 0; j < num3; j++)
					{
						rateHSV[array2[num2, 0]] = Mathf.InverseLerp(0f, this.texPickerSize[0].x, (float)j);
						rateHSV[array2[num2, 1]] = Mathf.InverseLerp(0f, this.texPickerSize[0].y, (float)i);
						array[i * num3 + j] = HsvColor.ToRgb(360f * rateHSV[0], rateHSV[1], rateHSV[2]);
					}
				}
			}
			else if (num == 1)
			{
				int[,] array3 = new int[,]
				{
					{
						2,
						1,
						0
					},
					{
						2,
						0,
						1
					},
					{
						0,
						1,
						2
					}
				};
				float[] rateRGB = base.GetRateRGB();
				for (int k = 0; k < num4; k++)
				{
					for (int l = 0; l < num3; l++)
					{
						rateRGB[array3[num2, 0]] = Mathf.InverseLerp(0f, this.texPickerSize[0].x, (float)l);
						rateRGB[array3[num2, 1]] = Mathf.InverseLerp(0f, this.texPickerSize[0].y, (float)k);
						array[k * num3 + l] = new Color(rateRGB[0], rateRGB[1], rateRGB[2]);
					}
				}
			}
			this.texPickerRect[0].SetPixels(array);
			this.texPickerRect[0].Apply();
		}

		// Token: 0x060022C3 RID: 8899 RVA: 0x000D18D8 File Offset: 0x000CFAD8
		public void ChangePickerSliderColor()
		{
			if (null == this.texPickerRect[1])
			{
				return;
			}
			//int num = (int)(this.pickerMode / UI_ColorPicker.PickerMode.Red);
			//int num2 = (int)(this.pickerMode % UI_ColorPicker.PickerMode.Red);
			int num = 0;
			int num2 = 1;
			int num3 = (int)this.texPickerSize[1].x;
			int num4 = (int)this.texPickerSize[1].y;
			Color[] array = new Color[num4 * num3];
			if (num == 0)
			{
				float[] rateHSV = base.GetRateHSV();
				if (num2 == 0)
				{
					rateHSV[1] = 1f;
					rateHSV[2] = 1f;
				}
				for (int i = 0; i < num4; i++)
				{
					for (int j = 0; j < num3; j++)
					{
						rateHSV[num2] = Mathf.InverseLerp(0f, this.texPickerSize[1].y, (float)i);
						array[i * num3 + j] = HsvColor.ToRgb(rateHSV[0] * 360f, rateHSV[1], rateHSV[2]);
					}
				}
			}
			else if (num == 1)
			{
				float[] rateRGB = base.GetRateRGB();
				for (int k = 0; k < num4; k++)
				{
					for (int l = 0; l < num3; l++)
					{
						rateRGB[num2] = Mathf.InverseLerp(0f, this.texPickerSize[1].y, (float)k);
						array[k * num3 + l] = new Color(rateRGB[0], rateRGB[1], rateRGB[2]);
					}
				}
			}
			this.texPickerRect[1].SetPixels(array);
			this.texPickerRect[1].Apply();
		}

		// Token: 0x060022C4 RID: 8900 RVA: 0x000D1A7C File Offset: 0x000CFC7C
		public void ChangePickerRectPos()
		{
			if (null == this.rtfPickerPos)
			{
				return;
			}
			switch (this.pickerMode)
			{
			case UI_ColorPicker.PickerMode.Hue:
			{
				float[] rateHSV = base.GetRateHSV();
				float x = this.imgPicker[0].rectTransform.sizeDelta.x * rateHSV[1];
				float y = this.imgPicker[0].rectTransform.sizeDelta.y * rateHSV[2];
				this.rtfPickerPos.anchoredPosition = new Vector2(x, y);
				break;
			}
			case UI_ColorPicker.PickerMode.Saturation:
			{
				float[] rateHSV2 = base.GetRateHSV();
				float x2 = this.imgPicker[0].rectTransform.sizeDelta.x * rateHSV2[0];
				float y2 = this.imgPicker[0].rectTransform.sizeDelta.y * rateHSV2[2];
				this.rtfPickerPos.anchoredPosition = new Vector2(x2, y2);
				break;
			}
			case UI_ColorPicker.PickerMode.Value:
			{
				float[] rateHSV3 = base.GetRateHSV();
				float x3 = this.imgPicker[0].rectTransform.sizeDelta.x * rateHSV3[0];
				float y3 = this.imgPicker[0].rectTransform.sizeDelta.y * rateHSV3[1];
				this.rtfPickerPos.anchoredPosition = new Vector2(x3, y3);
				break;
			}
			case UI_ColorPicker.PickerMode.Red:
			{
				float[] rateRGB = base.GetRateRGB();
				float x4 = this.imgPicker[0].rectTransform.sizeDelta.x * rateRGB[2];
				float y4 = this.imgPicker[0].rectTransform.sizeDelta.y * rateRGB[1];
				this.rtfPickerPos.anchoredPosition = new Vector2(x4, y4);
				break;
			}
			case UI_ColorPicker.PickerMode.Green:
			{
				float[] rateRGB2 = base.GetRateRGB();
				float x5 = this.imgPicker[0].rectTransform.sizeDelta.x * rateRGB2[2];
				float y5 = this.imgPicker[0].rectTransform.sizeDelta.y * rateRGB2[0];
				this.rtfPickerPos.anchoredPosition = new Vector2(x5, y5);
				break;
			}
			case UI_ColorPicker.PickerMode.Blue:
			{
				float[] rateRGB3 = base.GetRateRGB();
				float x6 = this.imgPicker[0].rectTransform.sizeDelta.x * rateRGB3[0];
				float y6 = this.imgPicker[0].rectTransform.sizeDelta.y * rateRGB3[1];
				this.rtfPickerPos.anchoredPosition = new Vector2(x6, y6);
				break;
			}
			}
		}

		// Token: 0x060022C5 RID: 8901 RVA: 0x000D1D24 File Offset: 0x000CFF24
		public void ChangePickerSliderPos()
		{
			if (null == this.pickerSlider)
			{
				return;
			}
			switch (this.pickerMode)
			{
			case UI_ColorPicker.PickerMode.Hue:
			{
				float[] rateHSV = base.GetRateHSV();
				this.pickerSlider.value = rateHSV[0];
				break;
			}
			case UI_ColorPicker.PickerMode.Saturation:
			{
				float[] rateHSV2 = base.GetRateHSV();
				this.pickerSlider.value = rateHSV2[1];
				break;
			}
			case UI_ColorPicker.PickerMode.Value:
			{
				float[] rateHSV3 = base.GetRateHSV();
				this.pickerSlider.value = rateHSV3[2];
				break;
			}
			case UI_ColorPicker.PickerMode.Red:
			{
				float[] rateRGB = base.GetRateRGB();
				this.pickerSlider.value = rateRGB[0];
				break;
			}
			case UI_ColorPicker.PickerMode.Green:
			{
				float[] rateRGB2 = base.GetRateRGB();
				this.pickerSlider.value = rateRGB2[1];
				break;
			}
			case UI_ColorPicker.PickerMode.Blue:
			{
				float[] rateRGB3 = base.GetRateRGB();
				this.pickerSlider.value = rateRGB3[2];
				break;
			}
			}
		}

		// Token: 0x060022C6 RID: 8902 RVA: 0x000D1E14 File Offset: 0x000D0014
		public void ChangePickerSliderAPos()
		{
			if (null == this.pickerSliderA)
			{
				return;
			}
			this.pickerSliderA.value = base.GetColorAlpha();
		}

		// Token: 0x040023D8 RID: 9176
		public UI_ColorPicker.PickerMode pickerMode;

		// Token: 0x040023D9 RID: 9177
		public Transform[] tfPickerMode = new Transform[Enum.GetValues(typeof(UI_ColorPicker.PickerMode)).Length];

		// Token: 0x040023DA RID: 9178
		public Slider pickerSlider;

		// Token: 0x040023DB RID: 9179
		public Slider pickerSliderA;

		// Token: 0x040023DC RID: 9180
		public Image[] imgPicker = new Image[2];

		// Token: 0x040023DD RID: 9181
		public UI_InfoPicker infoPicker;

		// Token: 0x040023DE RID: 9182
		public RectTransform rtfPickerPos;

		// Token: 0x040023DF RID: 9183
		private Texture2D[] texPickerRect = new Texture2D[2];

		// Token: 0x040023E0 RID: 9184
		private Vector2[] texPickerSize = new Vector2[2];

		// Token: 0x02000552 RID: 1362
		public enum PickerMode
		{
			// Token: 0x040023E2 RID: 9186
			Hue,
			// Token: 0x040023E3 RID: 9187
			Saturation,
			// Token: 0x040023E4 RID: 9188
			Value,
			// Token: 0x040023E5 RID: 9189
			Red,
			// Token: 0x040023E6 RID: 9190
			Green,
			// Token: 0x040023E7 RID: 9191
			Blue
		}
	}
}
